package cn.jh.common.pay.jdpush;

import java.util.Objects;

import static com.google.common.base.Strings.isNullOrEmpty;

/**
 * @author Yichuan
 * @version 1.0
 */
public enum WithdrawStatus {

    INIT("INIT", "提交"),

    REMITING("REMITING", "出款"),

    SUCCESS("SUCCESS", "成功"),

    FAIL("FAIL", "失败"),

    UNKNOW("UNKNOW", "未知"),

    ;

    final String value;

    final String desc;

    WithdrawStatus(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    public static WithdrawStatus of(String val) {
        return of(val, null);
    }
    public static WithdrawStatus of(String val, WithdrawStatus defaultStatus) {
        if (isNullOrEmpty(val)) {
            return defaultStatus;
        }
        val = val.toUpperCase();
        for (WithdrawStatus os: values()) {
            if (Objects.equals(os.getValue(), val)) {
                return os;
            }
        }
        return defaultStatus;
    }

    public static WithdrawStatus ofFail() {
        return WithdrawStatus.FAIL;
    }
}
